infobar: Avoid a memory leak in an error case
authorMatthias Clasen <mclasen@redhat.com>
Fri, 26 Feb 2016 19:55:20 +0000 (14:55 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 26 Feb 2016 20:52:19 +0000 (15:52 -0500)
Parsing <action-widgets> could sometimes fail to free
some of the data, if a nonexisting widget is referenced.
Found by gcc's leak sanitizer.

gtk/gtkinfobar.c

index d34ebfd36997ec3d86b240b00b0305ea0d3e71ce..e2c64fb0089842d497b8fcbbdebcecce8a3c61ab 100644 (file)
@@ -915,6 +915,15 @@ typedef struct
   gint col;
 } SubParserData;
 
+static void
+action_widget_info_free (gpointer data)
+{
+  ActionWidgetInfo *item = data;
+
+  g_free (item->name);
+  g_free (item);
+}
+
 static void
 parser_start_element (GMarkupParseContext  *context,
                       const gchar          *element_name,
@@ -1096,12 +1105,9 @@ gtk_info_bar_buildable_custom_finished (GtkBuildable *buildable,
       if (ad->response_id == GTK_RESPONSE_HELP)
         gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (info_bar->priv->action_area),
                                             GTK_WIDGET (object), TRUE);
-
-      g_free (item->name);
-      g_free (item);
     }
 
-  g_slist_free (data->items);
+  g_slist_free_full (data->items, action_widget_info_free);
   g_string_free (data->string, TRUE);
   g_slice_free (SubParserData, data);
 }